package com.ruoyi.project.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.StringUtils;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.product.domain.InsMachineBottleBarcodeTag;
import com.ruoyi.project.product.service.IInsMachineBottleBarcodeTagService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 瓶贴标签模板Controller
 *
 * @author taney
 * @date 2021-01-05
 */
@AllArgsConstructor
@RestController
@RequestMapping("/product/machineBottleBarcodeTag" )
public class InsMachineBottleBarcodeTagController extends BaseController {

    private final IInsMachineBottleBarcodeTagService iInsMachineBottleBarcodeTagService;

    /**
     * 查询瓶贴标签模板列表
     */
    @PreAuthorize("@ss.hasPermi('product:machineBottleBarcodeTag:list')")
    @GetMapping("/list")
    public TableDataInfo list(InsMachineBottleBarcodeTag insMachineBottleBarcodeTag)
    {
        startPage();
        LambdaQueryWrapper<InsMachineBottleBarcodeTag> lqw = new LambdaQueryWrapper<InsMachineBottleBarcodeTag>();
        if (StringUtils.isNotBlank(insMachineBottleBarcodeTag.getMachineType())){
            lqw.eq(InsMachineBottleBarcodeTag::getMachineType ,insMachineBottleBarcodeTag.getMachineType());
        }
        if (StringUtils.isNotBlank(insMachineBottleBarcodeTag.getTempName())){
            lqw.like(InsMachineBottleBarcodeTag::getTempName ,insMachineBottleBarcodeTag.getTempName());
        }
        if (insMachineBottleBarcodeTag.getTempCodeno() != null){
            lqw.eq(InsMachineBottleBarcodeTag::getTempCodeno ,insMachineBottleBarcodeTag.getTempCodeno());
        }
        List<InsMachineBottleBarcodeTag> list = iInsMachineBottleBarcodeTagService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出瓶贴标签模板列表
     */
    @PreAuthorize("@ss.hasPermi('product:machineBottleBarcodeTag:export')" )
    @Log(title = "瓶贴标签模板" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(InsMachineBottleBarcodeTag insMachineBottleBarcodeTag) {
        LambdaQueryWrapper<InsMachineBottleBarcodeTag> lqw = new LambdaQueryWrapper<InsMachineBottleBarcodeTag>(insMachineBottleBarcodeTag);
        List<InsMachineBottleBarcodeTag> list = iInsMachineBottleBarcodeTagService.list(lqw);
        ExcelUtil<InsMachineBottleBarcodeTag> util = new ExcelUtil<InsMachineBottleBarcodeTag>(InsMachineBottleBarcodeTag. class);
        return util.exportExcel(list, "machineBottleBarcodeTag" );
    }

    /**
     * 获取瓶贴标签模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:machineBottleBarcodeTag:query')" )
    @GetMapping(value = "/{bottleBarcodeTagTempId}" )
    public AjaxResult getInfo(@PathVariable("bottleBarcodeTagTempId" ) Integer bottleBarcodeTagTempId) {
        return AjaxResult.success(iInsMachineBottleBarcodeTagService.getById(bottleBarcodeTagTempId));
    }

    /**
     * 新增瓶贴标签模板
     */
    @PreAuthorize("@ss.hasPermi('product:machineBottleBarcodeTag:add')" )
    @Log(title = "瓶贴标签模板" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InsMachineBottleBarcodeTag insMachineBottleBarcodeTag) {
        return toAjax(iInsMachineBottleBarcodeTagService.save(insMachineBottleBarcodeTag) ? 1 : 0);
    }

    /**
     * 修改瓶贴标签模板
     */
    @PreAuthorize("@ss.hasPermi('product:machineBottleBarcodeTag:edit')" )
    @Log(title = "瓶贴标签模板" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InsMachineBottleBarcodeTag insMachineBottleBarcodeTag) {
        return toAjax(iInsMachineBottleBarcodeTagService.updateById(insMachineBottleBarcodeTag) ? 1 : 0);
    }

    /**
     * 删除瓶贴标签模板
     */
    @PreAuthorize("@ss.hasPermi('product:machineBottleBarcodeTag:remove')" )
    @Log(title = "瓶贴标签模板" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{bottleBarcodeTagTempIds}" )
    public AjaxResult remove(@PathVariable Integer[] bottleBarcodeTagTempIds) {
        return toAjax(iInsMachineBottleBarcodeTagService.removeByIds(Arrays.asList(bottleBarcodeTagTempIds)) ? 1 : 0);
    }
}
